package ru.ifmo.rybakov.muclumon;

import java.util.HashSet;
import java.util.Set;

public class TaskObserver {
	private final Set<ITaskListener> listeners = new HashSet<ITaskListener>();
	
	public void addListener(ITaskListener listener) {
		listeners.add(listener);
	}
	
	public void removeListener(ITaskListener listener) {
		listeners.add(listener);
	}
	
	public void notifyOnTaskStarted() {
		for (ITaskListener listener : listeners) {
			listener.onTaskStarted();
		}
	}
	
	public void notifyOnTaskStopped() {
		for (ITaskListener listener : listeners) {
			listener.onTaskStopped();
		}
	}
	
	protected TaskObserver() {}
	
	private static TaskObserver instance;
	
	public static TaskObserver getInstance() {
		if (instance == null) {
			instance = new TaskObserver();
		}
		return instance;
	}
}
